1214C - Bad Sequence - CodeForces Solution


data structures greedy *1200

Please click on ads to support us..

Python Code:

tamanho = input()
entrada = input()
lista = []
lista.append(entrada[0])
for i in range(1,len(entrada)):

    
    if entrada[i]=='(':
        lista.append('(')
    else:
        if len(lista)>0:
            if(entrada[i]==')' and lista[-1]=='('):
                lista.pop()
            else:
                lista.append(')')
        
        else:
            lista.append(')')


if(len(lista)==0):
    print('Yes')
elif len(lista)==2:
    if(lista[0]!=lista[1]):
        print("Yes")
    else:
        print('No')
else:
    print('No')


Comments

Submit
0 Comments
More Questions

873B - Balanced Substring
1401D - Maximum Distributed Tree
1716C - Robot in a Hallway
1688B - Patchouli's Magical Talisman
99A - Help Far Away Kingdom
622B - The Time
1688C - Manipulating History
1169D - Good Triple
1675B - Make It Increasing
588A - Duff and Meat
1541B - Pleasant Pairs
1626B - Minor Reduction
1680A - Minimums and Maximums
1713A - Traveling Salesman Problem
1713B - Optimal Reduction
1710A - Color the Picture
1686B - Odd Subarrays
251A - Points on Line
427C - Checkposts
1159A - A pile of stones
508A - Pasha and Pixels
912A - Tricky Alchemy
1249A - Yet Another Dividing into Teams
1713C - Build Permutation
1699A - The Third Three Number Problem
1617B - GCD Problem
841A - Generous Kefa
1690B - Array Decrements
1692C - Where's the Bishop
104A - Blackjack